#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int N = 120;
struct ss
{
	string xm, zw, xzw;
	int bg, dj, xh;
}a[N];
bool cmp1(ss x, ss y)
{
	if (x.bg != y.bg) return x.bg > y.bg;
	return x.xh < y.xh;
}
int compare(string x)
{
	if (x == "BangZhu") return 1;
	else if (x == "FuBangZhu") return 2;
	else if (x == "HuFa") return 3;
	else if (x == "ZhangLao") return 4;
	else if (x == "TangZhu") return 5;
	else if (x == "JingYing") return 6;
	else if (x == "BangZhong") return 7;
}
bool cmp2(ss x, ss y)
{
	if (x.xzw == y.xzw)
	{
		if (x.dj != y.dj)
			return x.dj > y.dj;
		else
			return x.xh < y.xh;
	}
	return compare(x.xzw) < compare(y.xzw);
}
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].xm >> a[i].zw >> a[i].bg >> a[i].dj;
		a[i].xh = i;
	}
	sort(a + 4, a + n + 1, cmp1);
	for (int i = 1; i <= n; i++)
	{
		if (i == 1) a[i].xzw = "BangZhu";
		else if (i == 2 || i == 3) a[i].xzw = "FuBangZhu";
		else if (i == 4 || i == 5) a[i].xzw = "HuFa";
		else if (i >= 6 && i <= 9) a[i].xzw = "ZhangLao";
		else if (i >= 10 && i <= 16) a[i].xzw = "TangZhu";
		else if (i >= 17 && i <= 41) a[i].xzw = "JingYing";
		else a[i].xzw = "BangZhong";
	}
	sort(a + 1, a + n + 1, cmp2);
	for (int i = 1; i <= n; i++)
		cout << a[i].xm << " " << a[i].xzw << " " << a[i].dj<<endl;
	return 0;
}